﻿using MediatR;
using Messhall.Domain.Permission.BusinessObjects;

namespace Messhall.Application.Permission.Commands;

/// <summary>
/// 创建用户
/// </summary>
public class CreateUsersCommandHandler : CommandHandlerBase, IRequestHandler<CreateUsersCommand, bool>
{
    public async Task<bool> Handle(CreateUsersCommand createUsersCommand, CancellationToken cancellationToken)
    {
        var request = createUsersCommand.Request;

        var user = new Users(new UsersEntity()
        {
            AccountNo = request.AccountNo,
            Integral = request.Integral,
            Mobile = request.Mobile,
            PassWord = request.PassWord,
            IsVip = request.IsVip,
            Money = request.Money,
            Name = request.Name,
        });

        await usersRepository.AddAsync(user);
        await appUnitOfWork.SaveChangesAsync(cancellationToken);

        return true;
    }
}